<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .prent {
            width: 100%;
            height: 300px;
            background-color: red;
            color: #fff;
        }

        .child {
            width: 100%;
            height: 100px;
            background-color: blue;
        }
    </style>
</head>

<body>
    <div id="root">

    </div>
</body>
<script src="../react.js"></script>
<script src="../react-dom.js"></script>
<!-- 用来将jsx语法转化为js语法 -->
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.js"></script>
<script type="text/babel">
    class App extends React.Component {
        state = {
            num: 0,
            user: {
                name: "王五",
                age: 18
            },
            sex: '男',
            obj: {
                name: '李四',
                age: 29,
                sex: '女',
                phone: 110
            }
        }
        render() {
            /* 
            1.父组件中 子组件标签上绑定一个自定义属性
            2.在子组件中 使用props获取父组件传递的自定义属性
            */
            return (
                <div className='prent'>
                    <h1>父组件----{this.state.num}</h1>
                    <button onClick={() => {
                        this.state.num++
                        this.setState({
                            num: this.state.num
                        })
                    }}>
                        ++</button>
                    <Child mynum={this.state.num} msg="张三" myuser={this.state.user} sex={this.state.sex} />
                    <ChildTwo{...this.state.obj} />
                    {
                        //<ChildTwo name={this.state.obj.name} age={this.obj.age}>
                    }
                </div>
            )
        }
    }
    /*
    组件本身没有办法改变props 想让其发生改变，只能由父组件改变
    */
    class Child extends React.Component {
        state = {

        }
        render() {
            console.log(this);
            return (
                <div className='child'>
                    <h1>子组件---{this.props.mynum}</h1>
                </div>
            )
        }
    }
    class ChildTwo extends React.Component {
        state = {

        }
        render() {
            console.log(this);
            return (
                <div>
                    <h1>childTwo组件</h1>
                </div>
            )
        }
    }
    ReactDOM.render(<App />, document.getElementById('root'));
</script>

</html>